package leetCode.sample;

public class AddStringsSolution {

    public static void main(String[] args) {
        int b = (2 << 5) - 2;
        int c = (int) (2 * (Math.pow(2, 5) - 1));
        System.out.println(b);
        System.out.println(c);
        System.out.println(Math.pow(2, 5));
        System.out.println(addStrings("123", "19"));
    }

    public static String addStrings(String num1, String num2) {
        if (num1 == null || num1.isEmpty()) {
            return num2;
        }
        if (num2 == null || num2.isEmpty()) {
            return num1;
        }
        int n1 = num1.length() - 1;
        int n2 = num2.length() - 1;
        StringBuilder result = new StringBuilder("");
        int dz = 0;
        while (n1 >= 0 || n2 >= 0) {
            int c1 = n1 >= 0 ? num1.charAt(n1) - '0' : 0;
            int c2 = n2 >= 0 ? num2.charAt(n2) - '0' : 0;
            int sum = c1 + c2 + dz;
            result.insert(0, sum % 10);
            dz = sum / 10;
            n1--;
            n2--;
        }
        if (dz != 0) {
            result.insert(0, 1);
        }
        return result.toString();
    }
}
